package com.after.saas.gateway.config;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;


/**
 * @Classname GatewaySwaggerResourcesConfig
 * @Description TODO
 * @auth after
 * @since 2021/9/15 20:57
 */
@Component
@Primary
public class GatewaySwaggerResourcesConfig implements SwaggerResourcesProvider {

    @Value("${swagger.projects}")
    private String[] projects;

    @Override
    public List<SwaggerResource> get() {
        List<SwaggerResource> collect = Arrays.asList(projects).stream().map(name -> {
            SwaggerResource sre = swaggerResource(name, "/" + name + "/v2/api-docs");
            return sre;
        }).collect(Collectors.toList());
        return collect;
    }

    private SwaggerResource swaggerResource(String serviceId, String location) {
        SwaggerResource sre = new SwaggerResource();
        sre.setName(serviceId);
        sre.setLocation(location);
        sre.setSwaggerVersion("version");
        return sre;
    }
}